/**
 * 
 */
package com.jm.web.builder.table;


import java.io.IOException;

import com.jm.utils.StringBuilderEx;
import com.jm.web.builder.BaseBuilder;
import com.jm.web.form.table.Table;
import com.jm.web.tags.support.BaseTag;
import com.jm.web.tags.table.TheadTag;

/**
 * @author yanjie
 *
 * 2011/9/22 下午1:39:03
 * Table 绘制器
 */
public class TheadBuilder extends BaseBuilder{
	protected TheadTag theadTag = null;
	
	@Override
	public void init(BaseTag tag) {
		super.init(tag);
		theadTag = (TheadTag)tag;
	}
	
	
	@Override
	protected void OutputTagBegin() {
		StringBuilderEx sb = new StringBuilderEx();
		//锁定表头
		if(Table.TAG_TABLE_STYLE_FIEXEDROW.equals(this.theadTag.getTableTag().getTable().getView())){
//			sb.Append("<DIV id='%1$s-head-div' class=\"header tableWrapper\" >",this.theadTag.getTableTag().getId());
//			sb.Append("<TABLE style=\"table-layout: fixed;\" cellspacing=\"0\" width=\"100%\" id=\""+this.theadTag.getTableTag().getId()+"-head\">");
//			sb.Append(this.theadTag.getTableTag().getTable().getColumnModel());
		}else{
			//當導出excel的時候不需要colgroup
			if(!this.getBaseTag().getPage().isExportFile())
				sb.Append(this.theadTag.getTableTag().getTable().getColumnModel());
		}
		try {
			this.getOut().write(sb.toString());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	@Override
	protected void OutputTagBody() {
		this.theadTag.getThead().onRender(this.getOut());
	}
	
	@Override
	protected void OutputTagEnd() {
		//锁定表头
		if(Table.TAG_TABLE_STYLE_FIEXEDROW.equals(this.theadTag.getTableTag().getTable().getView())){
//			StringBuilderEx sb = new StringBuilderEx();
//			sb.Append("</TABLE>");
//			sb.Append("</DIV>");
//			this.getWriter().write(sb.toString());
		}
	}
}
